package scene.present 
{
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;
	/**
	 * ...
	 * @author carlor
	 */
	public class PresentManager 
	{
		private var _list: Array;
		
		public function PresentManager() 
		{
			_list = new Array();
		}
		
		public function dispose(): void
		{
			clear();
			_list = null;
		}
		
		public function clear(): void
		{
			while (_list.length > 0) {
				var present: Present = _list.pop();
				present.dispose();
				present = null;
			}
		}
		
		public function addPresent(present: Present): Present
		{
			_list.push(present);
			
			return present;
		}
		
		public function update(curTime: int): void
		{
			var len: int = _list.length;
			for (var i: int = len - 1; i >= 0; i--) {
				var present: Present = _list[i];
				present.update(curTime);
				if (! present.moving) {
					_list.splice(i, 1);
					present.dispose();
					present = null;
				}
			}
		}
	}

}